package main

import (
    "fmt"
    "sync"
    "time"
)



type SaveCounter struct{
    v map[string] int
    mux sync.Mutex
}



func (c *SaveCounter) Inc(key string){
    c.mux.Lock()
    c.v[key]++
    c.mux.Unlock()
}

func(c *SaveCounter) Value(key string) int{
    c.mux.Lock()
    defer c.mux.Unlock()
    return c.v[key]
}


func main(){
    c :=  SaveCounter{v: make(map[string]int)}

    for i:= 0; i < 1000; i++{
        go c.Inc("somekey")
    }
    // todo how to wait finish
    time.Sleep(time.Second)
    fmt.Println(c.Value("somekey"))
}

